package com.dinggao.crossgo.core;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import com.dinggao.crossgo.core.constant.CommonConstant;
import com.dinggao.crossgo.core.dao.DaoMaster;
import com.dinggao.crossgo.core.dao.DaoSession;
import com.squareup.leakcanary.LeakCanary;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.crashreport.CrashReport;

import me.jessyan.autosize.AutoSizeConfig;


public class MainApplication extends Application {

    private static MainApplication ourInstance = new MainApplication();
    private static Context mContext;
    private static DaoSession daoSession;
    public static MainApplication getInstance() {
        return ourInstance;
    }

    public static Context getContext() {
        return mContext;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        LeakCanary.install(this);
        ourInstance = this;
        mContext = getApplicationContext();

        AutoSizeConfig.getInstance()
                .setUseDeviceSize(true)
                .setBaseOnWidth(false);
        setupDatabase();

        Bugly.init(getApplicationContext(), CommonConstant.BUGLY_APPID, false);
    }

    /**
     * 配置数据库
     */
    private void setupDatabase() {
        //获得数据库对象izar.db"
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CrossGo", null);
        //获取可写数据库
        SQLiteDatabase db = helper.getWritableDatabase();
        //获取数据库对象
        DaoMaster daoMaster = new DaoMaster(db);
        //获取Dao对象管理者
        daoSession = daoMaster.newSession();
    }

    public static DaoSession getDaoInstant() {
        return daoSession;
    }
}
